package storage

import (
	"context"

	"mall/service/wpgql/api/internal/graph/model"
)

func (m *MemoryStorage) PutMenuItem(ctx context.Context, menuItem *model.MenuItem) error {
	m.menuItems[menuItem.ID] = menuItem

	return nil
}

func (m *MemoryStorage) GetMenuItems(ctx context.Context, ids []string) ([]*model.MenuItem, error) {
	output := make([]*model.MenuItem, 0, len(ids))
	for _, id := range ids {
		if menuItem, ok := m.menuItems[id]; ok {
			output = append(output, menuItem)
		}
	}

	return output, nil
}

func (m *MemoryStorage) GetAllMenuItems(ctx context.Context) ([]*model.MenuItem, error) {
	output := make([]*model.MenuItem, 0, len(m.menuItems))
	for _, menuItem := range m.menuItems {
		output = append(output, menuItem)
	}

	return output, nil
}
